import pathway as pw
from typing import Dict, Any
from application.db.mysql_db.nsfc.NsfcResourceSourceDict import NsfcResourceSourceDict


class NsfcResourceSourceDictSchema(pw.Schema):
    source_id: str
    source_name: Dict[str, Any]
    source_main_link: str


class NsfcResourceSourceDictRead(pw.io.python.ConnectorSubject):
    
    def run(self):
        select_list = NsfcResourceSourceDict.select().dicts()
        for doc in select_list:
            doc = self.transform(doc)
            self.next(**doc)
    
    def transform(self, transform_data):
        transform_data = {k: v for k, v in transform_data.items()
                          if v is not None and v != {}}
        
        return transform_data